package com.atguigu.realtime.gmallpublisher2.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.realtime.gmallpublisher2.service.PublisherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author lzc
 * @Date 2020/11/24 16:45
 */
@RestController
public class PublisherController {

    @Autowired
    PublisherService service;

    @GetMapping("/trademark")
    public String trademark(String startDt, String endDt, int limit){
        Map<String, BigDecimal> map = service.getTMAmountSum(startDt, endDt, limit);

        ArrayList<Map<String, Object>> result = new ArrayList<>();
        for (Map.Entry<String, BigDecimal> entry : map.entrySet()) {
            HashMap<String, Object> tmp = new HashMap<>();
            String tm_name = entry.getKey();
            BigDecimal amount = entry.getValue();
            tmp.put("x", tm_name);
            tmp.put("y", amount);
            tmp.put("s", 1);
            result.add(tmp);
        }

        return JSON.toJSONString(result);
    }
}
